;(use-package elpy
;  :ensure t
;  :init
;  (elpy-enable))
(elpy-enable)
(when (require 'flycheck nil t)
  (setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
  (add-hook 'elpy-mode-hook 'flycheck-mode))

;; 设置虚拟环境
;; (pyvenv-activate "/opt/py/env/gu")
(setq elpy-rpc-virtualenv-path 'current) ;为elpy-config使用
;; 使用自带python
;; (setq python-shell-interpreter "/usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/bin/ipython")
(setq python-shell-interpreter "/usr/bin/python3")
(setq elpy-rpc-python-command "/usr/bin/python3")
;; (setq  python-shell-interpreter-args "-u")


;; (setq elpy-modules (delq 'elpy-module-flymake elpy-modules))

(setq compilation-scroll-output t)


(defun zzz()
  (interactive)
  (progn
    (elpy-shell-send-codecell)
    ;; (switch-to-buffer "*Python*")
    (next-multiframe-window)
    (end-of-buffer)
    ;; (previous-buffer)
    (next-multiframe-window)
    ))

  
(setq python-indent-offset 4)

;; (set-language-environment "UTF-8")
;; (setenv "PYTHONIOENCODING" "utf-8")
;; (add-to-list 'process-coding-system-alist '("elpy" . (utf-8 . utf-8)))
;; (add-to-list 'process-coding-system-alist '("python" . (utf-8 . utf-8)))
;; (add-to-list 'process-coding-system-alist '("flake8" . (utf-8 . utf-8)))



;; (add-hook 'inferior-python-mode 'auto-revert-mode)

(setq python-shell-unbuffered nil)
(setq python-shell-prompt-detect-failure-warning nil)
(setq python-shell-prompt-detect-enabled nil)
(setenv "IPY_TEST_SIMPLE_PROMPT" "1")
;; (global-set-key (kbd "C-M-k")                      'elpy-shell-send-region-or-buffer) ;;没有用

;; (add-hook 'python-mode-hook 'jedi:setup)
;; (setq jedi:complete-on-dot t)                 ; optional
;; (define-key elpy-mode-map (kbd "C-c C-c") 'elpy-shell-send-codecell)
(define-key elpy-mode-map (kbd "C-c C-c") 'zzz)
(define-key elpy-mode-map (kbd "<C-down>") 'forward-paragraph)
(define-key elpy-mode-map (kbd "<C-up>") 'backward-paragraph)
;; (define-key elpy-mode-map (kbd "M-.") 'elpy-goto-definition-or-rgrep)
;; end-of-buf
(defun org-flag-drawer (flag)
  "When FLAG is non-nil, hide the drawer we are within.
    Otherwise make it visible."
  (save-excursion
    (beginning-of-line 1)
    (when (looking-at "^[ \t]*:[a-zA-Z][a-zA-Z0-9]*:")
      (let ((b (match-end 0)))
        (if (re-search-forward
             "^[ \t]*:END:"
             (save-excursion (outline-next-heading) (point)) t)
            (outline-flag-region b (point-at-eol) flag)
          (user-error (concat (buffer-name) " :END: line missing at position %s" b)))))))

(provide 'py-config)
